package com.dayu.web.controller.share;

import java.util.List;

import com.dayu.share.domain.ShareGoods;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dayu.common.annotation.Log;
import com.dayu.common.core.controller.BaseController;
import com.dayu.common.core.domain.AjaxResult;
import com.dayu.common.enums.BusinessType;
import com.dayu.share.domain.ShareGoodsPrice;
import com.dayu.share.service.IShareGoodsPriceService;
import com.dayu.common.utils.poi.ExcelUtil;
import com.dayu.common.core.page.TableDataInfo;

/**
 * 商品报价Controller
 * 
 * @author HK
 * @date 2021-04-08
 */
@RestController
@RequestMapping("/share/price")
public class ShareGoodsPriceController extends BaseController
{
    @Autowired
    private IShareGoodsPriceService shareGoodsPriceService;

    /**
     * 查询商品报价列表
     */
    @PreAuthorize("@ss.hasPermi('share:price:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShareGoodsPrice shareGoodsPrice)
    {
        startPage();
        List<ShareGoodsPrice> list = shareGoodsPriceService.selectShareGoodsPriceList(shareGoodsPrice);
        return getDataTable(list);
    }

    /**
     * 导出商品报价列表
     */
    @PreAuthorize("@ss.hasPermi('share:price:export')")
    @Log(title = "商品报价", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ShareGoodsPrice shareGoodsPrice)
    {
        List<ShareGoodsPrice> list = shareGoodsPriceService.selectShareGoodsPriceList(shareGoodsPrice);
        ExcelUtil<ShareGoodsPrice> util = new ExcelUtil<ShareGoodsPrice>(ShareGoodsPrice.class);
        return util.exportExcel(list, "price");
    }

    /**
     * 获取商品报价详细信息
     */
    @PreAuthorize("@ss.hasPermi('share:price:query')")
    @GetMapping(value = "/{priceId}")
    public AjaxResult getInfo(@PathVariable("priceId") Long priceId)
    {
        return AjaxResult.success(shareGoodsPriceService.selectShareGoodsPriceById(priceId));
    }

    /**
     * 新增商品报价
     */
    @PreAuthorize("@ss.hasPermi('share:price:add')")
    @Log(title = "商品报价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShareGoods shareGoods)
    {
        return toAjax(shareGoodsPriceService.updateGoodsPriceListByGoodsId(shareGoods.getGoodsId()));
    }

    /**
     * 修改商品报价
     */
    @PreAuthorize("@ss.hasPermi('share:price:edit')")
    @Log(title = "商品报价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShareGoodsPrice shareGoodsPrice)
    {
        return toAjax(shareGoodsPriceService.updateShareGoodsPrice(shareGoodsPrice));
    }

    /**
     * 删除商品报价
     */
    @PreAuthorize("@ss.hasPermi('share:price:remove')")
    @Log(title = "商品报价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{priceIds}")
    public AjaxResult remove(@PathVariable Long[] priceIds)
    {
        return toAjax(shareGoodsPriceService.deleteShareGoodsPriceByIds(priceIds));
    }
}
